package com.kkb.controller;

import com.kkb.pojo.User;
import com.kkb.service.UserService;
import com.kkb.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author:CoolTiger
 * @title: UserController
 * @projectName ssm_hospital
 * @description: TODO 用户登陆、注册
 * @date:2022/07/08/15:12:20
 **/
@Controller
@RequestMapping("/hospital/user")
@ResponseBody
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public ResultUtil<User> login(HttpServletRequest request, HttpSession session, User user) {
        System.out.println(user);
        User login = userService.login(user);
        System.out.println(login);
        if (login != null) {
            session.setAttribute("username", user.getuLoginname());
//            model.addAttribute("username", user.getuLoginname());
            return new ResultUtil<User>(login);
        } else {
            request.setAttribute("msg","账号");
//            model.addAttribute("msg","账号或密码错误");
            return new ResultUtil<>(500, "账号或密码错误");
        }
    }
}
